<title>质量监督列表</title>
<!-- /section:settings.box -->
<div class="row quality_list">
	<div class="col-xs-12">
		<div class="ad_so">
			<select class="chosen-select" id="hx_area">
				<option>请选择区域</option>
				<?php
				if (is_array ( $area ) && count ( $area ) > 0) {
					foreach ( $area as $item ) {
						?>
									<option value="<?=$item['id']?>"><?=$item['sys_value']?></option>
									<?php
					}
				}
				?>
			</select> <input type="text" id="hx_name" class="input-large"
				placeholder="工程名称">
			<button type="button" class="btn btn-info serach">
				<i class="glyphicon glyphicon-search"></i> 搜索
			</button>
		</div>
		<div class="tabbable tabbable2">
			<ul class="nav nav-tabs padding-12 tab-color-blue background-blue">
				<li name="li_tab" data-identity="-1" class="active"><a
					href="javascript:;">全部登记（0）</a></li>
				<li name="li_tab" data-identity="1"><a href="javascript:;">受理通知（0）</a></li>
				<li name="li_tab" data-identity="2"><a href="javascript:;">质量监督（0）</a></li>
			</ul>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<div>
					<table class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>ID</th>
								<th>工程名称</th>
								<th>状态</th>
								<th>工程性质</th>
								<th>区域</th>
								<th>结构类型/层次</th>
								<th>建筑面积</th>
								<th>工程造价</th>
								<th>施工单位</th>
								<th>勘察单位</th>
								<th>监理单位</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody class="data" style="display: table-row-group;">

						</tbody>
					</table>
				</div>
			</div>
		</div>
		<!--分页-->
		<nav class="pull-right">
			<ul class="pagination">
				<li><a class="first" href="javascript:void(1);"
					aria-label="Previous"> 首页</a></li>
				<li><a class="prev" href="javascript:void(1);"><i
						class="ace-icon fa fa-angle-double-left"></i>上一页</a></li>
				<li><a class="next" href="javascript:void(1);">下一页<i
						class="ace-icon fa fa-angle-double-right"></i></a></li>
				<li><a class="last" href="javascript:void(1);" aria-label="Next">尾页</a>
				</li>
				<li><a class="go_page" href="javascript:void(1);">跳转到</a></li>
				<li><input type="text" style="width: 30px" class="go_num" value="1"></li>
				<li>页</li>
			</ul>
		</nav>
		<!-- TemplteHidden -->
		<table class="list-tpl hidden">
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>
					<button type="button" class="btn btn-mini btn-info notice"
						data-identity="notice" title="受理通知书">
						<i class="ace-icon glyphicon glyphicon-ok"> 受理通知书</i>
					</button>
					<button type="button" class="btn btn-mini btn-success supervision"
						data-identity="opinion" title="监督记录">
						<i class="ace-icon glyphicon glyphicon-retweet"> 监督记录</i>
					</button>
				</td>
			</tr>
		</table>
	</div>
</div>
<script type="text/javascript">
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	var $scope = $('.quality_list');
	function pageInit(page){
		$.getJSON(page.url,
		{
			page:page.pi
		},					
		function(ret)
		{
			if(ret.status>0)
			{
				var $data=$('.data',$scope);
				$data.hide();
				$data.empty();
				var data=ret.data;							
				pageObj.set_page_count_without_action(ret.page_count);
				$("li[name='li_tab'][data-identity='-1']>a",$scope).text("全部（"+ret.tct+"）");
				$("li[name='li_tab'][data-identity='1']>a",$scope).text("受理通知（"+ret.sltzct+"）");
				$("li[name='li_tab'][data-identity='2']>a",$scope).text("质量监督（"+ret.zljdct+"）");
				for(var i in data)
				{
					var $item=$('.list-tpl tr',$scope).clone();
					var v = data[i];
					var id = v['id'];
					$('td:eq(0)',$item).attr('data-identity','id-'+id).text(id);
					$('td:eq(1)',$item).text(v['name']);
					$('td:eq(2)',$item).text(v['status_str']);
					$('td:eq(3)',$item).text(v['nature_str']);
					$('td:eq(4)',$item).text(v['address_str']);
					$('td:eq(5)',$item).text(v['structure_type']);
					$('td:eq(6)',$item).text(v['area']);
					$('td:eq(7)',$item).text(v['cost']);
					$('td:eq(8)',$item).text(v['construction_unit']);
					$('td:eq(9)',$item).text(v['reconnaissance_unit']);
					$('td:eq(10)',$item).text(v['supervision_units_name']);
					$('td:eq(11) .notice',$item).attr('data-identity','notice-'+id);	
					$('td:eq(11) .supervision',$item).attr('data-identity','supervision-'+id);					
					$data.append($item);
				}
				$data.show();
			}
			else {
				pageObj.set_page_count_without_action(1);
				message_box.show(ret.data,'error');
			}
		});
	}
	//分页代码
	pageObj=new pagination({
		'url':'/quality/ajax_quality_list',
		'page_count':9,
		'show_callback':function(page){										
			pageInit(page);
		}
	});
	$('.first', $scope).click(function() {
		pageObj.first_page();
		$('.go_num', $scope).val('1');
	});
	$('.prev', $scope).click(function() {
		pageObj.prev_page();
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	$('.next', $scope).click(function() {
		pageObj.next_page();
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	$('.last', $scope).click(function() {
		pageObj.last_page();
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	//跳转输入框
	$('.go_num', $scope).change(function() {
		var num = $(this).val();
		if (num > pageObj.get_page_count()) {
			$(this).val(pageObj.get_page_count());
		} else if (num < 1) {
			$(this).val(1);
		}
	})
	//跳转至指定页面
	$('.go_page', $scope).click(function() {
		var num = $('.go_num', $scope).val();
		pageObj.go_page(num);
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	$scope.delegate('[data-identity="add"]', 'click', function() {
		var url = '/quality/add';
		gDialog.fCreate({
			title: '质量监督-增加',
			url: url,
			width: 700
		}).show();
	}).delegate('[data-identity^="notice"]','click',function(){
		var id=$(this).attr('data-identity').split('-')[1];
		var url='/quality/notice?id='+id;
		gDialog.fCreate({title:'受理通知书',url: url,width:800}).show();
	}).delegate('[data-identity^="supervision"]','click',function(){
		var id=$(this).attr('data-identity').split('-')[1];
		var url='/quality/supervision?id='+id;
		gDialog.fCreate({title:'监督记录',url: url,width:600}).show();
	});
	function create_where() {
		var p_name = $("#hx_name", $scope).val() || "";
		var area = $("hx_area", $scope).val() || "";
		var tb = $("li[name='li_tab'][class='active']", $scope).attr("data-identity");
		var where = "?pname=" + p_name + "&tb=" +
			tb + "&area=" + area;
		return where;
	}
	$("li[name='li_tab']", $scope).click(function() {
		$("li[name='li_tab']").removeClass("active");
		$(this).addClass("active");
		url = '/quality/ajax_quality_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 9,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
	$('.serach', $scope).click(function() {
		var url = '/quality/ajax_quality_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 9,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
})
</script>
